<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<html>

<!--
	Copyright (c) 1999-2008 by Digital Mars
	All Rights Reserved
	Written by Walter Bright
	www.digitalmars.com
  -->

<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" >
<title>std.md5 - D Programming Language - Digital Mars</title>
<link rel="stylesheet" type="text/css" href="./style.css">
<link rel="icon" type="image/gif" href="./holy.gif" />
</head>

<body>
<div id="heading">
	<a href="http://www.digitalmars.com/"><img src="./dmlogo.gif" width="270" height="53" border="0" alt="www.digitalmars.com" align="left"></a>
	<p align="right">D Programming Language 1.0</p>


	<div id="headingNav">
	<ul>
	<li><a href="http://www.prowiki.org/wiki4d/wiki.cgi?DocComments/Phobos/StdMd5" title="Read/write comments and feedback">Comments</a></li>
	<li><a href="http://www.digitalmars.com/d/1.0/index.html" title="D Programming Language" class="dlink">D</a></li>
	<li><a href="http://www.digitalmars.com/advancedsearch.html" title="Search Digital Mars web site">Search</a></li>
	<li><a href="http://www.digitalmars.com/" title="www.digitalmars.com">Home</a></li>
	</ul>
	</div>

	<div id="lastupdate">Last update Wed Oct  1 23:47:52 2008</div>
</div>

<!-- -->

<div id="navigation">
    <div class="navblock">
<form method="get" action="http://www.google.com/search">
<div id="searchbox">
<input id="q" name="q" size="10" value="RTL Search" onFocus='if(this.value == "RTL Search"){this.value="";}'>
<input type="hidden" id="domains" name="domains" value="www.digitalmars.com">
<input type="hidden" id="sitesearch" name="sitesearch" value="www.digitalmars.com/d/1.0/phobos">
<input type="hidden" id="sourceid" name="sourceid" value="google-search">
<input type="submit" id="submit" name="submit" value="Go">
</div>
</form>
<div id="toctop">
    <ul>
	<li><a href="http://www.digitalmars.com/d/1.0/index.html" title="D Programming Language">D ...</a></li>
	<li><a href="http://www.digitalmars.com/d/1.0/lex.html" title="D Language Specification">Language ...</a></li>
	<li><a href="phobos.html" title="D Runtime Library">Phobos ...</a></li>
	<li><a href="http://www.digitalmars.com/d/1.0/comparison.html" title="Language Comparisons">Comparisons ...</a></li>
    </ul>
</div>
</div>
    <div class="navblock">
<ul>
<li><a href="index.html" title="Index of all HTML files">Index</a></li>
</ul>
    <ul>
	<li><a href="object.html" title="root of object hierarchy">object</a></li>
    </ul>
    <h2><a href="phobos.html#std" title="D standard modules">std</a></h2>
    <ul>
	<li><a href="std.base64.html" title="Encode/decode base64 format">std.base64</a></li>
	<li><a href="std.bind.html" title="Function argument binding">std.bind</a></li>
	<li><a href="std.bitarray.html" title="Arrays of bits">std.bitarray</a></li>
	<li><a href="std.boxer.html" title="Box/unbox types">std.boxer</a></li>
	<li><a href="std.compiler.html" title="Information about the D compiler implementation">std.compiler</a></li>
	<li><a href="std.conv.html" title="Conversion of strings to integers">std.conv</a></li>
	<li><a href="std.cover.html" title="D coverage analyzer">std.cover</a></li>
	<li><a href="std.cpuid.html" title="CPU identification">std.cpuid</a></li>
	<li><a href="std.ctype.html" title="Simple character classification">std.ctype</a></li>
	<li><a href="std.date.html" title="Date and time functions">std.date</a></li>
	<li><a href="std.demangle.html" title="Demangle D names">std.demangle</a></li>
	<li><a href="std.file.html" title="Basic file operations">std.file</a></li>
	<li><a href="std.format.html" title="Formatted conversions of values to strings">std.format</a></li>
	<li><a href="std.gc.html" title="Control the garbage collector">std.gc</a></li>
	<li><a href="std.intrinsic.html" title="Compiler built in intrinsic functions">std.intrinsic</a></li>
	<li><a href="std.math.html" title="the usual math functions">std.math</a></li>
	<li><a href="std.md5.html" title="Compute MD5 digests">std.md5</a></li>
	<li><a href="std.metastrings.html" title="Metaprogramming with strings">std.metastrings</a></li>
	<li><a href="std.mmfile.html" title="Memory mapped files">std.mmfile</a></li>
	<li><a href="std.openrj.html" title="Basic database">std.openrj</a></li>
	<li><a href="std.outbuffer.html" title="Assemble data into an array of bytes">std.outbuffer</a></li>
	<li><a href="std.outofmemory.html" title="Out of memory exception">std.outofmemory</a></li>
	<li><a href="std.path.html" title="Manipulate file names, path names, etc.">std.path</a></li>
	<li><a href="std.process.html" title="Create/destroy threads">std.process</a></li>
	<li><a href="std.random.html" title="Random number generation">std.random</a></li>
	<li><a href="std.regexp.html" title="regular expressions">std.regexp</a></li>
	<li><a href="std.signals.html" title="Signals">std.signals</a></li>
	<li><a href="std.socket.html" title="Sockets">std.socket</a></li>
	<li><a href="std.socketstream.html" title="Stream for a blocking, connected Socket">std.socketstream</a></li>
	<li><a href="std.stdint.html" title="Integral types for various purposes">std.stdint</a></li>
	<li><a href="std.stdio.html" title="Standard I/O">std.stdio</a></li>
	<li><a href="std.cstream.html" title="Stream I/O">std.cstream</a></li>
	<li><a href="std.stream.html" title="Stream I/O">std.stream</a></li>
	<li><a href="std.string.html" title="Basic string operations">std.string</a></li>
	<li><a href="std.system.html" title="Inquire about the CPU, operating system">std.system</a></li>
	<li><a href="std.thread.html" title="Thread operations">std.thread</a></li>
	<li><a href="std.traits.html" title="Type traits">std.traits</a></li>
	<li><a href="std.typetuple.html" title="Type tuples">std.typetuple</a></li>
	<li><a href="std.uni.html" title="Unicode classification">std.uni</a></li>
	<li><a href="std.uri.html" title="Encode and decode Uniform Resource Identifiers (URIs)">std.uri</a></li>
	<li><a href="std.utf.html" title="Encode and decode utf character encodings">std.utf</a></li>
	<li><a href="std.zip.html" title="Read/write zip archives">std.zip</a></li>
	<li><a href="std.zlib.html" title="Compression / Decompression of data">std.zlib</a></li>
	<li><a href="std.c.fenv.html" title="Floating point environment">std.c.fenv</a></li>
	<li><a href="std.c.locale.html" title="Locale">std.c.locale</a></li>
	<li><a href="std.c.math.html" title="Math">std.c.math</a></li>
	<li><a href="std.c.process.html" title="Process">std.c.process</a></li>
	<li><a href="std.c.stdarg.html" title="Variadic arguments">std.c.stdarg</a></li>
	<li><a href="std.c.stddef.html" title="Standard definitions">std.c.stddef</a></li>
	<li><a href="std.c.stdio.html" title="Standard I/O">std.c.stdio</a></li>
	<li><a href="std.c.stdlib.html" title="Standard library">std.c.stdlib</a></li>
	<li><a href="std.c.string.html" title="Strings">std.c.string</a></li>
	<li><a href="std.c.time.html" title="Time">std.c.time</a></li>
	<li><a href="std.c.wcharh.html" title="Wide characters">std.c.wcharh</a></li>
	<li><a href="std.windows.charset.html" title="Conversion to/from Windows character sets">std.windows.charset</a></li>
	<li><a href="phobos.html#std_windows" title="Modules specific to Windows">std.windows</a></li>
	<li><a href="phobos.html#std_linux" title="Modules specific to Windows">std.linux</a></li>
	<li><a href="phobos.html#std_c_windows" title="C Windows API">std.c.windows</a></li>
	<li><a href="phobos.html#std_c_linux" title="C Linux API">std.c.linux</a></li>
    </ul>
</div>
</div>
<div id="content">
    <h1><a href="./htmlsrc/std.md5.html">std.md5</a></h1>
    
Computes MD5 digests of arbitrary data. MD5 digests are 16 byte quantities that are like a checksum or crc, but are more robust. <br><br>
There are two ways to do this. The first does it all in one function call to
 sum&#40;&#41;. The second is for when the data is buffered. <br><br> <br><br>
<span style="color:red">BUGS:</span><br>
MD5 digests have been demonstrated to not be unique.<br><br>
<b>Author:</b><br>The routines and algorithms are derived from the
 <i>RSA Data Security, Inc. MD5 Message-Digest Algorithm</i>.<br><br>
<b>References:</b><br><a href="http://en.wikipedia.org/wiki/Md5">Wikipedia on MD5</a><br><br>
<b>Example:</b><br><pre class="d_code">

<span class="lc">// This code is derived from the</span>
<span class="lc">// RSA Data Security, Inc. MD5 Message-Digest Algorithm.</span>

<span class="k">import</span> <span class="i">std</span>.<span class="i">md5</span>;

<span class="k">private</span> <span class="k">import</span> <span class="i">std</span>.<span class="i">stdio</span>;
<span class="k">private</span> <span class="k">import</span> <span class="i">std</span>.<span class="i">string</span>;
<span class="k">private</span> <span class="k">import</span> <span class="i">std</span>.<span class="i">c</span>.<span class="i">stdio</span>;
<span class="k">private</span> <span class="k">import</span> <span class="i">std</span>.<span class="i">c</span>.<span class="i">string</span>;

<span class="k">int</span> <span class="i">main</span>(<span class="k">char</span>[][] <span class="i">args</span>)
{
    <span class="k">foreach</span> (<span class="k">char</span>[] <span class="i">arg</span>; <span class="i">args</span>)
	 <span class="i">MDFile</span>(<span class="i">arg</span>);
    <span class="k">return</span> <span class="n">0</span>;
}

<span class="bc">/* Digests a file and prints the result. */</span>
<span class="k">void</span> <span class="i">MDFile</span>(<span class="k">char</span>[] <span class="i">filename</span>)
{
    <span class="i">FILE</span>* <span class="i">file</span>;
    <span class="i">MD5_CTX</span> <span class="i">context</span>;
    <span class="k">int</span> <span class="i">len</span>;
    <span class="k">ubyte</span>[<span class="n">4</span> * <span class="n">1024</span>] <span class="i">buffer</span>;
    <span class="k">ubyte</span> <span class="i">digest</span>[<span class="n">16</span>];

    <span class="k">if</span> ((<span class="i">file</span> = <span class="i">fopen</span>(<span class="i">std</span>.<span class="i">string</span>.<span class="i">toStringz</span>(<span class="i">filename</span>), <span class="sl">"rb"</span>)) == <span class="k">null</span>)
	<span class="i">writefln</span>(<span class="sl">"%s can't be opened"</span>, <span class="i">filename</span>);
    <span class="k">else</span>
    {
	<span class="i">context</span>.<span class="i">start</span>();
	<span class="k">while</span> ((<span class="i">len</span> = <span class="i">fread</span>(<span class="i">buffer</span>, <span class="n">1</span>, <span class="i">buffer</span>.<span class="i">sizeof</span>, <span class="i">file</span>)) != <span class="n">0</span>)
	    <span class="i">context</span>.<span class="i">update</span>(<span class="i">buffer</span>[<span class="n">0</span> .. <span class="i">len</span>]);
	<span class="i">context</span>.<span class="i">finish</span>(<span class="i">digest</span>);
	<span class="i">fclose</span>(<span class="i">file</span>);

	<span class="i">writefln</span>(<span class="sl">"MD5 (%s) = %s"</span>, <span class="i">filename</span>, <span class="i">digestToString</span>(<span class="i">digest</span>));
    }
}

</pre><br><br>
<dl>
<dt><big>void <a href="./htmlsrc/std.md5.html#L102" title="At line 102.">sum</a>(ubyte[16] <i>digest</i>, void[] <i>data</i>);</big></dt>
<dd>
Computes MD5 digest of array of data.
 <br><br></dd>
<dt><big>void <a href="./htmlsrc/std.md5.html#L114" title="At line 114.">printDigest</a>(ubyte digest[16] <i>digest</i>);</big></dt>
<dd>
Prints a message digest in hexadecimal to stdout.
 <br><br></dd>
<dt><big>char[] <a href="./htmlsrc/std.md5.html#L124" title="At line 124.">digestToString</a>(ubyte[16] <i>digest</i>);</big></dt>
<dd>
Converts MD5 digest to a string.
 <br><br></dd>
<dt><big>struct <a href="./htmlsrc/std.md5.html#L143" title="At line 143.">MD5_CTX</a>;</big></dt>
<dd>
Holds context of MD5 computation.<br><br>
Used when data to be digested is buffered.
 <br><br>
<dl>
<dt><big>uint state[4] <a href="./htmlsrc/std.md5.html#L145" title="At line 145.">state</a>;</big></dt>
<dd></dd>
<dt><big>ulong <a href="./htmlsrc/std.md5.html#L149" title="At line 149.">count</a>;</big></dt>
<dd></dd>
<dt><big>ubyte buffer[64] <a href="./htmlsrc/std.md5.html#L150" title="At line 150.">buffer</a>;</big></dt>
<dd></dd>
<dt><big>ubyte[64] <a href="./htmlsrc/std.md5.html#L152" title="At line 152.">PADDING</a>; [static]</big></dt>
<dd></dd>
<dt><big>uint <a href="./htmlsrc/std.md5.html#L163" title="At line 163.">F</a>(uint <i>x</i>, uint <i>y</i>, uint <i>z</i>); [private, static]</big></dt>
<dd></dd>
<dt><big>uint <a href="./htmlsrc/std.md5.html#L164" title="At line 164.">G</a>(uint <i>x</i>, uint <i>y</i>, uint <i>z</i>); [private, static]</big></dt>
<dd></dd>
<dt><big>uint <a href="./htmlsrc/std.md5.html#L165" title="At line 165.">H</a>(uint <i>x</i>, uint <i>y</i>, uint <i>z</i>); [private, static]</big></dt>
<dd></dd>
<dt><big>uint <a href="./htmlsrc/std.md5.html#L166" title="At line 166.">I</a>(uint <i>x</i>, uint <i>y</i>, uint <i>z</i>); [private, static]</big></dt>
<dd></dd>
<dt><big>uint <a href="./htmlsrc/std.md5.html#L171" title="At line 171.">ROTATE_LEFT</a>(uint <i>x</i>, uint <i>n</i>); [static]</big></dt>
<dd></dd>
<dt><big>void <a href="./htmlsrc/std.md5.html#L192" title="At line 192.">FF</a>(inout uint <i>a</i>, uint <i>b</i>, uint <i>c</i>, uint <i>d</i>, uint <i>x</i>, uint <i>s</i>, uint <i>ac</i>); [static]</big></dt>
<dd></dd>
<dt><big>void <a href="./htmlsrc/std.md5.html#L199" title="At line 199.">GG</a>(inout uint <i>a</i>, uint <i>b</i>, uint <i>c</i>, uint <i>d</i>, uint <i>x</i>, uint <i>s</i>, uint <i>ac</i>); [static]</big></dt>
<dd></dd>
<dt><big>void <a href="./htmlsrc/std.md5.html#L206" title="At line 206.">HH</a>(inout uint <i>a</i>, uint <i>b</i>, uint <i>c</i>, uint <i>d</i>, uint <i>x</i>, uint <i>s</i>, uint <i>ac</i>); [static]</big></dt>
<dd></dd>
<dt><big>void <a href="./htmlsrc/std.md5.html#L213" title="At line 213.">II</a>(inout uint <i>a</i>, uint <i>b</i>, uint <i>c</i>, uint <i>d</i>, uint <i>x</i>, uint <i>s</i>, uint <i>ac</i>); [static]</big></dt>
<dd></dd>
<dt><big>void <a href="./htmlsrc/std.md5.html#L223" title="At line 223.">start</a>();</big></dt>
<dd>
MD5 initialization. Begins an MD5 operation, writing a new context.
     <br><br></dd>
<dt><big>void <a href="./htmlsrc/std.md5.html#L232" title="At line 232.">update</a>(void[] <i>input</i>);</big></dt>
<dd>
MD5 block update operation. Continues an MD5 message-digest
      operation, processing another message block, and updating the
      context.
     <br><br></dd>
<dt><big>void <a href="./htmlsrc/std.md5.html#L267" title="At line 267.">finish</a>(ubyte[16] <i>digest</i>);</big></dt>
<dd>
MD5 finalization. Ends an MD5 message-digest operation, writing the
 the message to digest and zeroing the context.
     <br><br></dd>
<dt><big>enum;</big></dt>
<dd>
<dl>
<dt><big><a href="./htmlsrc/std.md5.html#L299" title="At line 299.">S11</a></big></dt>
<dd></dd>
<dt><big><a href="./htmlsrc/std.md5.html#L300" title="At line 300.">S12</a></big></dt>
<dd></dd>
<dt><big><a href="./htmlsrc/std.md5.html#L301" title="At line 301.">S13</a></big></dt>
<dd></dd>
<dt><big><a href="./htmlsrc/std.md5.html#L302" title="At line 302.">S14</a></big></dt>
<dd></dd>
<dt><big><a href="./htmlsrc/std.md5.html#L303" title="At line 303.">S21</a></big></dt>
<dd></dd>
<dt><big><a href="./htmlsrc/std.md5.html#L304" title="At line 304.">S22</a></big></dt>
<dd></dd>
<dt><big><a href="./htmlsrc/std.md5.html#L305" title="At line 305.">S23</a></big></dt>
<dd></dd>
<dt><big><a href="./htmlsrc/std.md5.html#L306" title="At line 306.">S24</a></big></dt>
<dd></dd>
<dt><big><a href="./htmlsrc/std.md5.html#L307" title="At line 307.">S31</a></big></dt>
<dd></dd>
<dt><big><a href="./htmlsrc/std.md5.html#L308" title="At line 308.">S32</a></big></dt>
<dd></dd>
<dt><big><a href="./htmlsrc/std.md5.html#L309" title="At line 309.">S33</a></big></dt>
<dd></dd>
<dt><big><a href="./htmlsrc/std.md5.html#L310" title="At line 310.">S34</a></big></dt>
<dd></dd>
<dt><big><a href="./htmlsrc/std.md5.html#L311" title="At line 311.">S41</a></big></dt>
<dd></dd>
<dt><big><a href="./htmlsrc/std.md5.html#L312" title="At line 312.">S42</a></big></dt>
<dd></dd>
<dt><big><a href="./htmlsrc/std.md5.html#L313" title="At line 313.">S43</a></big></dt>
<dd></dd>
<dt><big><a href="./htmlsrc/std.md5.html#L314" title="At line 314.">S44</a></big></dt>
<dd></dd></dl></dd>
<dt><big>void <a href="./htmlsrc/std.md5.html#L317" title="At line 317.">transform</a>(ubyte* <i>block</i>); [private]</big></dt>
<dd></dd>
<dt><big>void <a href="./htmlsrc/std.md5.html#L411" title="At line 411.">Encode</a>(ubyte * <i>output</i>, uint * <i>input</i>, uint <i>len</i>); [private, static]</big></dt>
<dd></dd>
<dt><big>void <a href="./htmlsrc/std.md5.html#L428" title="At line 428.">Decode</a>(uint * <i>output</i>, ubyte * <i>input</i>, uint <i>len</i>); [private, static]</big></dt>
<dd></dd></dl></dd>
<dt><big><a href="./htmlsrc/std.md5.html#L447" title="At line 447.">unittest</a>;</big></dt>
<dd></dd></dl>
    <br><br>
<br><br>
<!-- Google ad -->
<script type="text/javascript"><!--
/**/google_ad_client = "pub-5628673096434613";
/**/google_ad_width = 728;
/**/google_ad_height = 90;
/**/google_ad_format = "728x90_as";
/**/google_ad_channel ="6203743411";
/**/google_page_url = document.location;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>


<div id="copyright">
Copyright &copy; 1999-2008 by Digital Mars, All Rights Reserved |
Page generated by <a href="http://code.google.com/p/dil">dil</a> on Wed Oct  1 23:47:52 2008
</div>

</body>
</html>